<?php
/*
*	Template Name: Homepage
*/
?>
<?php get_header(); ?>
<div class="container" id="top_info">
	<div class="top-content">&nbsp;</div>
    <div class="top-curve">&nbsp;</div>
</div>

<div id="main">
	<div class="featured">
	<?php
		$args = array(
			'post_type' => 'dmci_projects',
			'meta_query' => array(
				array(
					'key' => 'featured-project',
					'value' => 'yes',
					'compare' => 'LIKE'
				)
			)
		 );
		$query = new WP_Query( $args );
	
		if( $query->have_posts() ) : 
			while($query->have_posts() ):
				$query->the_post(); 
				
				$proj_title = get_the_title();
				
				$proj_link = get_permalink();
				$proj_location = wp_get_post_terms(get_the_ID(), 'dmci_project_locations', array('fields' => 'names') );
				
				?>
				
				<div class="fbox">
					<a href="<?php echo $proj_link; ?>" class="fcontent">
						
						<div class="fimg"><?php echo get_the_post_thumbnail( $post->ID, array('478', '278') ); ?></div>
						<div class="ftitle">
							<span class="main"><?php echo $proj_title; ?></span>
							<span class="sub"><?php  echo isset($proj_location[0]) ? $proj_location[0] : ''; ?></span>
						</div>
						<div class="fmain">
							<span class="title"><?php echo $proj_title; ?></span>
							<span class="desc"><?php  echo substr(get_the_excerpt(), 0, 300).' [...]';   ?></span>
							<span class="read-more">Read More</span>
						</div>
						<div class="clear">&nbsp;</div>
					</a>
				</div>
		<?php endwhile;
		endif;
		 wp_reset_query();
	?>
	</div>
	
	<div class="news">
		
		<h3>Construction Updates</h3>
       
		<?php
		$args = array(
			'post_type' => 'dmci_cons_update',
			'meta_key' => 'cons_update_date',
			'orderby' => 'meta_value',
			'order' => 'DESC',
			'posts_per_page' => 6,
		);
		$query = new WP_Query( $args );
	
		if( $query->have_posts() ) : 
			while($query->have_posts() ):
				$query->the_post(); 
				$proj_permalink = get_permalink();
				$the_date = get_post_meta($post->ID, 'cons_update_date', true);
				$query_args = array(
					'connected_type' => 'projects_to_consupdate',
					'connected_items' => intval(get_the_ID()),        
					'nopaging' => true
				);
				$project_query = new WP_Query($query_args);
				
				if($project_query->have_posts()):
				$project_query->the_post(); 
		?>
			
				<div class="news-block">
					<a href="<?php echo $proj_permalink . '?p_id=' . $post->p2p_to; ?>">
					<?php echo get_the_post_thumbnail( $post->ID, array('120', '120') ); ?>
					<div class="update-info">
						<div class="date"><?php echo $the_date ? date("F-j-Y", strtotime($the_date) ) : ''; ?></div>
						<div class="title"><?php the_title();?></div>
					</div>
					</a>
				</div>
					
				<?php endif; ?>
				
		<?php 
			endwhile; 
			endif;
			
			 wp_reset_query();
		?>
        
		<div class="clear">&nbsp;</div>
	</div>
    
    <a href="/all-project-updates/" id="viewAll">
    	<span class="line">&nbsp;</span>
        <div class="link">
        <span class="arrow">></span>
        View All
        </div>
    </a>
    
    <div class="clear">&nbsp;</div>
    
</div>

<?php get_footer(); ?>